<%@ page language="java" pageEncoding="utf-8"%>
<%@ include file="/commons/taglibs.jsp"%>
<html>
<head>
<title>新增/更新操作类型</title>
<%@ include file="/commons/meta.jsp" %>
<%@ include file="/commons/header.jsp" %>
<%@ include file="/extjs/jsps/importExt.jsp" %>
<%@ include file="/extjs/jsps/importEasyExt.jsp" %>
<script language="javascript" type="text/javascript">
var saveCounter=0;

function closeCurrentWindow() {
	var winId='${winId}';
	var closeWin=Ext.WindowMgr.get(winId);
	if(closeWin==null){
		closeWin=parent.Ext.WindowMgr.get(winId);
	}
	if(closeWin==null){
		window.returnValue=(saveCounter>0);
		window.close();
	}else{
		closeWin.returnValue=(saveCounter>0);
		closeWin.close();
	}
}

var formPanel = new Ext.form.FormPanel({
	bodyStyle: 'padding:5 5 5 5;',
	layout: 'form',
	autoWidth: true,
	autoScroll: true,
	labelAlign: 'right',
	labelWidth: 55,
	defaultType: 'textfield',
	defaults: {
		allowBlank: true,
		anchor: '100%',
		msgTarget: 'qtip'
	},
	items: [{
		xtype: 'hidden',
		name: 'id'
	},{
		allowBlank: false,
		fieldLabel: '名称',
		name: 'name',  
		maxLength: 32
	},{
		allowBlank: false,
		xtype: 'textarea',
		fieldLabel: '关键字',
		name: 'value'
	},{
       	fieldLabel: '备注',
       	xtype: 'textarea',
		name: 'memo'
	}],
	listeners: {
		afterRender: function(thiz) {
			var id='${id}';
			if(!Ext.isEmpty(id)&&id!='null') {
				var url='${ctx}/operation!getJSON.action';
				var params={
						id: id
				};
				Common.loadForm(thiz,url,params);
			}
		}
	},
		bbar: [{
		iconCls: 'acceptBtn',
		text: '保存',
		handler: function() {
			if (!formPanel.getForm().isValid(false)) return;
			var action;
			var id='${id}';
			var isUpdate=!Ext.isEmpty(id)&&id!='null';
			if(isUpdate) {
				action='updateJSON';
			}else {
				action='insertJSON';
			}
			formPanel.getForm().submit({
				method: 'post',
				waitTitle: ' ',
				waitMsg: '正在提交数据, 请稍后... ...',
				url: '${ctx}/operation!'+action+'.action',
				params: {},
				failure: function(form,action) {
					Ext.Msg.hide();
		        	Common.parseFailureResponse(action.response);
				},
				success: function(form,action) {
					var result = action.result;
					Common.parse(result,function(buttonId) {
						Ext.Msg.hide();
						if(result.pass||buttonId=='yes') {
							++saveCounter;
							closeCurrentWindow();
						}
					});
				}
			});
		}
	},'-',{
		iconCls: 'delete2Btn',
		text: '取消',
		handler: function() {
			closeCurrentWindow();
		}
	}]
});

Ext.onReady(function() {
	var viewport = new Ext.Viewport({
		layout: 'fit',
		items: [formPanel]
	});
});
</script>
</head>

<body>
</body>
</html>